#include <common/macro/build.h>

#include <query/iterator.h>
#include <query/query.h>
#include <query/result.h>
#include <query/iterators/ftscan.h>

API_LIBLOCAL inline result_e query_iterator_prepare(query_t *query, query_iterator_openpage_f openpage, query_iterator_closepage_f closepage) {
	query->iterator.pointer.page_number = 0;
	query->iterator.pointer.page_item = 0;
	query->iterator.page = NULL;
	query->iterator.tuple = NULL;

	query->iterator.openpage = openpage;
	query->iterator.closepage = closepage;
	query->iterator.status = QUERY_ITERATOR_OPEN;

	/* 
	 * When indices are enabled, we'll decide upon
	 * iterator plan (indexed or full table scan),
	 * and if necessary, prepare the scanner. Similar
	 * thing applies for step and finalize.
	 */
	return RESULT_OK;
}

API_LIBLOCAL inline result_e query_iterator_step(query_t *query) {
	return query_iterator_ftscan_step(query);
}

API_LIBLOCAL inline result_e query_iterator_finalize(query_t *query) {
	enum result_e result;

	result = query_iterator_ftscan_finalize(query);
	query->iterator.status = QUERY_ITERATOR_CLOSED;
	return result;
}
